#include <pluginui/manager/spi/SinglePanelContainerFactory.h>

namespace antu
{
namespace plugin
{
namespace ui
{
SinglePanelContainerFactory::SinglePanelContainerFactory()
{
}

AbstractPanelContainer *SinglePanelContainerFactory::createContainer(const QString &name, const QString &title, Qt::DockWidgetArea area, Qt::DockWidgetAreas allowedAreas, QDockWidget::DockWidgetFeatures features)
{
    return new SinglePanelContainer(name, title, area, allowedAreas, features);
}

void SinglePanelContainer::addToContainer(PanelItem *pPanelItem, int)
{
    Q_ASSERT(pPanelItem != nullptr);
    Q_ASSERT(pPanelItem->widget() != nullptr);

    if (this->m_oPanelItems.size() > 0)
        return;

    QHBoxLayout* pLayout = new QHBoxLayout;
    this->m_pWidget->setLayout(pLayout);
    this->m_pWidget->layout()->addWidget(pPanelItem->widget());
    this->m_oPanelItems.push_back(pPanelItem);

    if (this->changeWindowTitleWithTab())
    {
        this->m_pWidget->setWindowTitle(pPanelItem->widget()->windowTitle());
    }
}

void SinglePanelContainer::setChangeWindowTitleWithTab(bool changeWithTab)
{
    this->m_bChangeWindowTitleWithTab = changeWithTab;

    if (this->m_bChangeWindowTitleWithTab && this->m_oPanelItems.size() > 0)
    {
        this->m_pWidget->setWindowTitle(this->m_oPanelItems.at(0)->widget()->windowTitle());
    }
}

}
}
}
